package com.ssy.lingxi.member.merchant.controller.mobile;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.*;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.UserUpdateEmailVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.UserUpdatePasswordVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.UserUpdatePayPasswordVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.UserUpdatePhoneVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.UserAccountAuthQueryVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.UserAccountSecurityQueryVO;
import com.ssy.lingxi.member.merchant.service.web.IMemberAccountSecurityService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author 万宁
 * @version 2.0.0
 * @menu App - 账户安全相关接口
 * @date 2020-07-06
 */
@RestController
@RequestMapping("/member/mobile/security")
public class MobileAccountSecurityController {
    @Resource
    private IMemberAccountSecurityService userAccountSecurityService;


    /**
     * 账户安全-实名验证-保存身份证信息
     * @param headers Http头部信息
     * @param userAuthInfoVO 实名信息请求体
     * @return 操作结果
     */
    @RequestMapping(value = "/saveAuthInfo", method = RequestMethod.POST)
    public Wrapper<Void> saveAuthInfo(@RequestHeader HttpHeaders headers,@RequestBody @Valid UserAuthInfoVO userAuthInfoVO) {
        return userAccountSecurityService.saveAuthInfo(headers,userAuthInfoVO);
    }

    /**
     * 账户安全-实名验证-上传身份证信息
     *
     * @return 操作结果
     */
    @RequestMapping(value = "/uploadIdCard", method = RequestMethod.POST)
    public Wrapper<UserAccountAuthQueryVO> uploadIdCard(@RequestBody @Valid UserUploadIdCardVO userUploadIdCardVO) {
        return userAccountSecurityService.uploadIdCard(userUploadIdCardVO);
    }

    /**
     * 账户安全-实名验证-显示已实名认证的信息
     *
     * @param headers Http头部信息
     * @return 操作结果
     */
    @RequestMapping(value = "/getUserInfo", method = RequestMethod.GET)
    public Wrapper<UserAccountAuthQueryVO> getUserInfo(@RequestHeader HttpHeaders headers) {
        return userAccountSecurityService.getUserInfo(headers);
    }


    /**
     * “账户安全”页面，查询用户的手机号码和邮箱，以掩码方式返回
     *
     * @param headers Http头部信息
     * @return 操作结果
     */
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public Wrapper<UserAccountSecurityQueryVO> getPhoneAndEmail(@RequestHeader HttpHeaders headers) {
        return userAccountSecurityService.getPhoneAndEmail(headers);
    }

    /**
     * （通用）检查支付密码是否正确
     *
     * @param headers       Http头部信息
     * @param payPasswordVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/pay/check", method = RequestMethod.POST)
    public Wrapper<Void> checkPayPassword(@RequestHeader HttpHeaders headers, @RequestBody @Valid PayPasswordVO payPasswordVO) {
        return userAccountSecurityService.checkPayPassword(headers, payPasswordVO);
    }

    /**
     * 修改登录密码（手机校验码验证）时，发送手机短信验证码
     *
     * @param headers Http头部信息
     * @return 操作结果
     */
    @RequestMapping(value = "/psw/sms", method = RequestMethod.POST)
    public Wrapper<Void> sendChangePasswordSmsCode(@RequestHeader HttpHeaders headers) {
        return userAccountSecurityService.sendChangePasswordSmsCode(headers);
    }

    /**
     * 修改登录密码（手机校验码验证）时，检查手机短信验证码是否正确
     *
     * @param headers   Http头部信息
     * @param smsCodeVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/psw/sms/check", method = RequestMethod.POST)
    public Wrapper<Void> checkChangePasswordSmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid SmsCodeVO smsCodeVO) {
        return userAccountSecurityService.checkChangePasswordSmsCode(headers, smsCodeVO);
    }

    /**
     * 修改登录密码（邮箱验证）时，发送邮件验证码
     *
     * @param headers Http头部信息
     * @return 发送结果
     */
    @RequestMapping(value = "/psw/email", method = RequestMethod.POST)
    public Wrapper<Void> sendChangePasswordEmailCode(@RequestHeader HttpHeaders headers) {
        return userAccountSecurityService.sendChangePasswordEmailCode(headers);
    }

    /**
     * 修改登录密码（邮箱验证）时，检查邮件验证码是否正确
     *
     * @param headers   Http头部信息
     * @param smsCodeVO 接口参数
     * @return 发送结果
     */
    @RequestMapping(value = "/psw/email/check", method = RequestMethod.POST)
    public Wrapper<Void> checkChangePasswordEmailCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid SmsCodeVO smsCodeVO) {
        return userAccountSecurityService.checkChangePasswordEmailCode(headers, smsCodeVO);
    }

    /**
     * 修改登录密码
     *
     * @param userManageVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/psw/update", method = RequestMethod.POST)
    public Wrapper<Void> changePassword(@RequestHeader HttpHeaders headers, @RequestBody @Valid UserUpdatePasswordVO userManageVO) {
        return userAccountSecurityService.changePassword(headers, userManageVO);
    }

    /**
     * 修改邮箱（手机校验码验证）时，发送手机短信验证码
     *
     * @param headers Http头部信息
     * @return 操作结果
     */
    @RequestMapping(value = "/email/sms", method = RequestMethod.POST)
    public Wrapper<Void> sendChangeEmailSmsCode(@RequestHeader HttpHeaders headers) {
        return userAccountSecurityService.sendChangeEmailSmsCode(headers);
    }

    /**
     * 修改邮箱（手机校验码验证）时，检查手机短信验证码是否正确
     *
     * @param headers   Http头部信息
     * @param smsCodeVO 接口参数
     * @return 验证结果
     */
    @RequestMapping(value = "/email/sms/check", method = RequestMethod.POST)
    public Wrapper<Void> checkChangeEmailSmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid SmsCodeVO smsCodeVO) {
        return userAccountSecurityService.checkChangeEmailSmsCode(headers, smsCodeVO);
    }

    /**
     * 修改邮箱（邮箱验证）时，发送邮件验证码
     *
     * @param headers Http头部信息
     * @return 发送结果
     */
    @RequestMapping(value = "/email/email", method = RequestMethod.POST)
    public Wrapper<Void> sendChangeEmailEmailCode(@RequestHeader HttpHeaders headers) {
        return userAccountSecurityService.sendChangeEmailEmailCode(headers);
    }

    /**
     * 修改邮箱（邮箱验证）时，检查邮件验证码是否正确
     *
     * @param headers   Http头部信息
     * @param smsCodeVO 接口参数
     * @return 发送结果
     */
    @RequestMapping(value = "/email/email/check", method = RequestMethod.POST)
    public Wrapper<Void> checkChangeEmailEmailCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid SmsCodeVO smsCodeVO) {
        return userAccountSecurityService.checkChangeEmailEmailCode(headers, smsCodeVO);
    }

    /**
     * 修改邮箱时，向新邮箱发送邮件验证码
     *
     * @param headers Http头部信息
     * @param emailVO 接口参数
     * @return 发送结果
     */
    @RequestMapping(value = "/email/email/tonew", method = RequestMethod.POST)
    public Wrapper<Void> sendChangeEmailEmailCodeToNew(@RequestHeader HttpHeaders headers, @RequestBody @Valid EmailVO emailVO) {
        return userAccountSecurityService.sendChangeEmailEmailCodeToNew(headers, emailVO);
    }

    /**
     * 修改邮箱
     *
     * @param headers      Http头部信息
     * @param userManageVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/email/update", method = RequestMethod.POST)
    public Wrapper<Void> changeEmail(@RequestHeader HttpHeaders headers, @RequestBody @Valid UserUpdateEmailVO userManageVO) {
        return userAccountSecurityService.changeEmail(headers, userManageVO);
    }

    /**
     * 修改手机号码（手机校验码验证）时，发送手机短信验证码
     *
     * @param headers Http头部信息
     * @return 操作结果
     */
    @RequestMapping(value = "/phone/sms", method = RequestMethod.POST)
    public Wrapper<Void> sendChangePhoneSmsCode(@RequestHeader HttpHeaders headers) {
        return userAccountSecurityService.sendChangePhoneSmsCode(headers);
    }

    /**
     * 修改手机号码（手机校验码验证）时，检查手机短信验证码是否正确
     *
     * @param headers   Http头部信息
     * @param smsCodeVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/phone/sms/check", method = RequestMethod.POST)
    public Wrapper<Void> checkChangePhoneSmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid SmsCodeVO smsCodeVO) {
        return userAccountSecurityService.checkPhoneSmsCode(headers, smsCodeVO);
    }

    /**
     * 修改手机号码（邮箱验证）时，发送邮件验证码
     *
     * @param headers Http头部信息
     * @return 操作结果
     */
    @RequestMapping(value = "/phone/email", method = RequestMethod.POST)
    public Wrapper<Void> sendChangePhoneEmailCode(@RequestHeader HttpHeaders headers) {
        return userAccountSecurityService.sendChangePhoneEmailCode(headers);
    }

    /**
     * 修改手机号码（邮箱验证）时，检查邮件验证码是否正确
     *
     * @param headers   Http头部信息
     * @param smsCodeVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/phone/email/check", method = RequestMethod.POST)
    public Wrapper<Void> checkChangePhoneEmailCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid SmsCodeVO smsCodeVO) {
        return userAccountSecurityService.checkChangePhoneEmailCode(headers, smsCodeVO);
    }

    /**
     * 修改手机号码时，向新手机号码发送短信验证码
     *
     * @param headers Http头部信息
     * @param phoneVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/phone/sms/tonew", method = RequestMethod.POST)
    public Wrapper<Void> sendChangePhoneSmsCodeToNew(@RequestHeader HttpHeaders headers, @RequestBody @Valid PhoneVO phoneVO) {
        return userAccountSecurityService.sendChangePhoneSmsCodeToNew(headers, phoneVO);
    }

    /**
     * 修改手机号码时，检查向新手机号码发送的短信验证码是否正确
     *
     * @param headers   Http头部信息
     * @param smsCodeVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/phone/sms/check/new", method = RequestMethod.POST)
    public Wrapper<Void> checkNewPhoneSmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid PhoneSmsVO smsCodeVO) {
        return userAccountSecurityService.checkNewPhoneSmsCode(headers, smsCodeVO);
    }

    /**
     * 修改手机号
     *
     * @param headers      Http头部信息
     * @param userManageVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/phone/update", method = RequestMethod.POST)
    public Wrapper<Void> changePhone(@RequestHeader HttpHeaders headers, @RequestBody @Valid UserUpdatePhoneVO userManageVO) {
        return userAccountSecurityService.changePhone(headers, userManageVO);
    }

    /**
     * 重置支付密码时，发送手机短信验证码
     *
     * @param headers Http头部信息
     * @return 操作结果
     */
    @RequestMapping(value = "/pay/sms", method = RequestMethod.POST)
    public Wrapper<Void> sendChangePayPswSmsCode(@RequestHeader HttpHeaders headers) {
        return userAccountSecurityService.sendChangePayPswSmsCode(headers);
    }

    /**
     * 重置支付密码时，检查手机短信验证码是否正确
     *
     * @param headers   Http头部信息
     * @param smsCodeVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/pay/sms/check", method = RequestMethod.POST)
    public Wrapper<Void> checkChangePayPswSmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid SmsCodeVO smsCodeVO) {
        return userAccountSecurityService.checkChangePayPswSmsCode(headers, smsCodeVO);
    }

    /**
     * 修改支付密码
     *
     * @param headers      Http头部信息
     * @param userManageVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/pay/update", method = RequestMethod.POST)
    public Wrapper<Void> changePayPassword(@RequestHeader HttpHeaders headers, @RequestBody @Valid UserUpdatePayPasswordVO userManageVO) {
        return userAccountSecurityService.changePayPassword(headers, userManageVO);
    }
}
